package com.abel.repository.helper;

import java.util.*;

public class StaticCodesLoader {

	private static StaticCodesLoader scl;
	  
	   //Build all static lists/maps; this may be replaced later by a file lookup

	  private static List eduTypeList = new ArrayList();
	  private static Map eduTypeMap = new HashMap();
	  private static Map eduTypeDescMap = new HashMap();
	  
	  private static List ynList = new ArrayList();
	  private static Map ynMap = new HashMap();
	  private static Map ynDescMap = new HashMap();
	  
	  private static List ynnaList = new ArrayList();
	  private static Map ynnaMap = new HashMap();
	  private static Map ynnaDescMap = new HashMap();
	  
	  private static List stateList = new ArrayList();
	  private static Map stateMap = new HashMap();  
	  private static Map stateDescMap = new HashMap();
	  
	  private StaticCodesLoader() {    
	  }

	  public static StaticCodesLoader getInstance() {
	    if(scl==null)
	      scl = new StaticCodesLoader();
	    
	    return scl;
	  }
	  
	  public boolean chkMapValue(String listName, Object dbValue)
	  {
	     if (listName.equals("ynna")) {
	        if (ynnaMap.get(dbValue)!=null){
	            return true;
	        }
	        else
	        {
	            return false;
	        }
	     } 
	     else
	      return false;
	  }

	  public List getynList() {
	    return ynList;
	  }

	  public StaticCode getYnCode(Object dbValue) {
	    return (StaticCode)ynMap.get(dbValue);
	  }  
	  
	  public StaticCode getYnCodeByDesc(Object dbValue) {
	    return (StaticCode)ynDescMap.get(dbValue);
	  }      
	   
	  public List getynnaList() {
	    return ynnaList;
	  }
	 
	  public StaticCode getYnnaCode(Object dbValue) {
	    return (StaticCode)ynnaMap.get(dbValue);
	  }
	  public StaticCode getYnnaCodeByDesc(Object dbValue) {
	    return (StaticCode)ynnaDescMap.get(dbValue);
	  }

	  public StaticCode getStateCode(Object dbValue) {
	    return (StaticCode)stateMap.get(dbValue);
	  }  
	 
	  public StaticCode getStateCodeByDesc(Object dbValue) {
	    return (StaticCode)stateDescMap.get(dbValue);
	  } 
	  

	  //Build all static lists/maps; this may be replaced later by a file lookup
	  
	  
	  static {
	    
	    eduTypeList.add(new StaticCode("C", "College"));
	    eduTypeList.add(new StaticCode("HS", "Hish School"));
	    eduTypeList.add(new StaticCode("ADV", "Advance/Special Education"));
	    eduTypeMap = buildMap(eduTypeList);
	    eduTypeDescMap = buildDescMap(eduTypeList);

	    ynList.add(new StaticCode("N", "No"));
	    ynList.add(new StaticCode("Y", "Yes"));
	    ynMap = buildMap(ynList);
	    ynDescMap = buildDescMap(ynList);

	    ynnaList.add(new StaticCode("N", "No"));
	    ynnaList.add(new StaticCode("Y", "Yes"));
	    ynnaList.add(new StaticCode("NA", "Not Applicable"));
	    ynnaMap = buildMap(ynnaList);
	    ynnaDescMap = buildDescMap(ynnaList);
	    
	    stateList.add(new StaticCode("AL", "Alabama")); 
	    stateList.add(new StaticCode("AK", "Alaska")); 
	    stateList.add(new StaticCode("AZ", "Arizona"));
	    stateList.add(new StaticCode("AR", "Arkansas"));
	    stateList.add(new StaticCode("CA", "California"));
	    stateList.add(new StaticCode("CO", "Colorado"));
	    stateList.add(new StaticCode("CT", "Connecticut"));
	    stateList.add(new StaticCode("DE", "Delaware"));
	    stateList.add(new StaticCode("DC", "District of Columbia"));
	    stateList.add(new StaticCode("FL", "Florida"));
	    stateList.add(new StaticCode("GA", "Georgia"));
	    stateList.add(new StaticCode("HI", "Hawaii"));
	    stateList.add(new StaticCode("ID", "Idaho"));
	    stateList.add(new StaticCode("IL", "Illinois"));
	    stateList.add(new StaticCode("IN", "Indiana"));
	    stateList.add(new StaticCode("IA", "Iowa"));
	    stateList.add(new StaticCode("KS", "Kansas"));
	    stateList.add(new StaticCode("KY", "Kentucky"));
	    stateList.add(new StaticCode("LA", "Louisiana"));
	    stateList.add(new StaticCode("ME", "Maine"));
	    stateList.add(new StaticCode("MD", "Maryland"));
	    stateList.add(new StaticCode("MA", "Massachusetts"));
	    stateList.add(new StaticCode("MI", "Michigan"));
	    stateList.add(new StaticCode("MN", "Minnesota"));
	    stateList.add(new StaticCode("MS", "Mississippi"));
	    stateList.add(new StaticCode("MO", "Missouri"));
	    stateList.add(new StaticCode("MT", "Montana"));
	    stateList.add(new StaticCode("NE", "Nebraska"));
	    stateList.add(new StaticCode("NV", "Nevada"));
	    stateList.add(new StaticCode("NH", "New Hampshire"));
	    stateList.add(new StaticCode("NJ", "New Jersey"));
	    stateList.add(new StaticCode("NM", "New Mexico"));
	    stateList.add(new StaticCode("NY", "New York"));
	    stateList.add(new StaticCode("NC", "North Carolina"));
	    stateList.add(new StaticCode("ND", "North Dakota"));
	    stateList.add(new StaticCode("OH", "Ohio"));
	    stateList.add(new StaticCode("OK", "Oklahoma"));
	    stateList.add(new StaticCode("OR", "Oregon"));
	    stateList.add(new StaticCode("PA", "Pennsylvania"));
	    stateList.add(new StaticCode("RI", "Rhode Island"));
	    stateList.add(new StaticCode("SC", "South Carolina"));
	    stateList.add(new StaticCode("SD", "South Dakota"));
	    stateList.add(new StaticCode("TN", "Tennessee"));
	    stateList.add(new StaticCode("TX", "Texas"));
	    stateList.add(new StaticCode("UT", "Utah"));
	    stateList.add(new StaticCode("VT", "Vermont"));
	    stateList.add(new StaticCode("VI", "Virginia"));
	    stateList.add(new StaticCode("WA", "Washington"));
	    stateList.add(new StaticCode("WV", "West Virginia"));
	    stateList.add(new StaticCode("WI", "Wisconsin"));
	    stateList.add(new StaticCode("WY", "Wyoming"));
	    stateMap = buildMap(stateList);         
	    stateDescMap = buildDescMap(stateList);
	  }
	  
	  private static final Map buildMap(List codeList) {
	    Map codeMap = new HashMap(codeList.size());
	    for(Iterator it = codeList.iterator(); it.hasNext();) {
	      StaticCode code = (StaticCode)it.next();
	      //codeMap.put(code.getDbValue(), code);
	      //Lookups from tag will always fail if key is not a String
	      codeMap.put(code.getDbValue().toString(), code);
	    }
	    return codeMap;
	  }
	  private static final Map buildDescMap(List codeList) {
	    Map codeMap = new HashMap(codeList.size());
	    for(Iterator it = codeList.iterator(); it.hasNext();) {
	      StaticCode code = (StaticCode)it.next();
	      codeMap.put( code.getDescription(),code);
	    }
	    return codeMap;
	  }
}
